/**
 * @description:
 * @file: common.ts
 * @author: Evan
 * @date: 2025.04.14 14:31:10
 * @week: 周一
 * @version: V
 * */

import { mock } from 'mockjs'
import { builder } from '../util'
import type { MockResponse } from '../type'

export default [
  // 测试
  {
    url: '/test',
    method: 'get',
    response: () => {
      return builder('请求成功')
    }
  },
  // 模型转换上传文件
  {
    url: '/model/upload',
    method: 'get',
    response: () => {
      console.log('上传操作', new Date())
      return builder('上传操作')
    }
  },
  // 能源类型
  {
    url: '/energy/category',
    method: 'get',
    response: () => {
      return builder(
        mock({
          'list|6': [
            {
              id: '@id',
              'name|+1': ['综合能耗', '电能', '水', '燃气', '蒸汽', '冷量'],
              'code|+1': ['TOTAL', 'ELECTRICITY', 'WATER', 'GAS', 'STEAM', 'COOL'],
              'icon|+1': ['zonghe', 'dian', 'shui', 'ranqi', 'zhengqi', 'lengliang']
            }
          ]
        }).list
      )
    }
  },
  // 能耗分项
  {
    url: '/energy/sub_category',
    method: 'get',
    response: (e: MockResponse) => {
      const type = e.query.type
      if (type === 'TOTAL') return []
      return builder(
        mock({
          'list|0-5': [
            {
              'name|+1': ['空调', '照明', '电梯', '动力', '其他'],
              id: '@id'
            }
          ]
        }).list
      )
    }
  },
  // 时间颗粒度
  {
    url: '/time/type',
    method: 'get',
    response: () => {
      return builder(
        mock({
          'list|6': [
            {
              'name|+1': ['小时', '日', '周', '月', '季', '年'],
              'code|+1': ['hour', 'day', 'week', 'month', 'season', 'year']
            }
          ]
        }).list
      )
    }
  },
  // 维度树结构
  {
    url: '/dimension/tree',
    method: 'get',
    response: (e: MockResponse) => {
      const type = e.query.nodeType || 0
      const name = ['区域', '部门', '班组', '系统', '支路', '分项'][type]
      const list = ['A', 'B', 'C', 'D'].map(it => it + name)
      return builder(
        mock({
          'list|1-3': [
            {
              id: '@id',
              'name|+1': list,
              'children|1-3': [
                {
                  id: '@id',
                  'name|+1': list.map(it => it + '-二级'),
                  'children|1-3': [
                    {
                      id: '@id',
                      'name|+1': list.map(it => it + '-三级')
                    }
                  ]
                }
              ]
            }
          ]
        }).list
      )
    }
  },
  // 下拉列表
  {
    url: '/select/list',
    method: 'get',
    response: (e: MockResponse) => {
      const name = e.query.name || ''
      const list = 'ABCDEFGHIJKLMN'.split('').map(it => it + name)
      const len = list.length
      return builder(
        mock({
          [`list|1-${len}`]: [
            {
              id: '@id',
              'name|+1': list
            }
          ]
        }).list
      )
    }
  },
  // 下拉树
  {
    url: '/select/tree',
    method: 'get',
    response: (e: MockResponse) => {
      const name = e.query.name || ''
      const list = 'ABCDEFGHIJKLMN'.split('').map(it => it + name)
      const len = list.length
      return builder(
        mock({
          [`list|1-${len}`]: [
            {
              id: '@id',
              'name|+1': list,
              [`children|1-${len}`]: [
                {
                  id: '@id',
                  'name|+1': list.map(it => it + '-二级'),
                  [`children|1-${len}`]: [
                    {
                      id: '@id',
                      'name|+1': list.map(it => it + '-三级')
                    }
                  ]
                }
              ]
            }
          ]
        }).list
      )
    }
  },
  // 表格分页
  {
    url: '/table/page',
    method: 'get',
    response: (e: MockResponse) => {
      const { page = 1, pageSize = Math.floor(Math.random() * 5 + 3) } = e.query || {}
      return builder(
        mock({
          page: page,
          'total|0-100': 0,
          [`data|${pageSize}-${pageSize}`]: [
            {
              id: '@id',
              name: '@cword(2, 5)',
              key1: '@cword(2, 3)',
              key2: '@cword(2, 3)',
              key3: '@cword(2, 3)',
              key4: '@cword(2, 3)',
              key5: '@cword(2, 3)',
              key6: '@cword(2, 3)',
              key7: '@cword(2, 3)',
              key8: '@cword(2, 3)',
              key9: '@cword(2, 3)',
              key10: '@cword(2, 3)',
              'status|0-1': 0,
              'status1|0-1': 0,
              'status2|0-1': 0,
              'status3|0-1': 0,
              'status4|0-1': 0,
              'level|0-10': 0,
              'level1|0-10': 0,
              'level2|0-10': 0
            }
          ]
        })
      )
    }
  },
  // 表格详情
  {
    url: '/table/get',
    method: 'get',
    response: (e: MockResponse) => {
      const { id, min = 0, max = 1000 } = e.query || {}
      const res: AnyObject = {
        id: id,
        name: mock('@cword(2, 5)'),
        status: mock({ 'number|0-1': 0 }).number
      }
      for (let i = 1; i < 20; i++) {
        res['key' + i] = mock('@cword(2, 5)')
        res['value' + i] = mock({ [`number|${min}-${max}.0-2`]: 0 }).number
      }
      for (let i = 0; i < 5; i++) {
        res['status' + i] = mock({ 'number|0-1': 0 }).number
        res['level' + i] = mock({ 'number|0-20': 0 }).number
        res['percent' + i] = mock({ 'number|90-99.0-2': 0 }).number
        res['rate' + i] = mock({ 'number|0-99.0-2': 0 }).number
        res['temp' + i] = mock({ 'number|35-40.0-2': 0 }).number
        res['tempmax' + i] = mock({ 'number|40-45.0-2': 0 }).number
        res['pass' + i] = mock({ 'number|95-99.0-2': 0 }).number
        res['date' + i] = mock('@date("yyyy-MM-dd")')
        res['datetime' + i] = mock('@date("yyyy-MM-dd HH:mm:ss")')
      }
      return builder(res)
    }
  }
]
